<template>
  <div class="box">
    <!-- 右侧固定定位的小图标 -->
    <div class="audioOverLay" v-if="data.audio">
      <div class="radius">
        <div class="small"></div>
      </div>
    </div>

    <HeaderTop :isActive="isActive" :data="'长篇'"></HeaderTop>

    <div class="contents" v-if="data.json_content">
      <div class="title">{{ data.title }}</div>
      <div class="author">
        {{ data.json_content.simple_author[0] }}
      </div>
      <!-- 文章主体内容 -->
      <div
        class="contitle"
        v-if="data.json_content"
        v-html="data.json_content.content"
      ></div>

      <!-- 文章底部作者及编辑人的信息与评论  拆分成组件，方便复用-->
      <editor :edit="data" :comments="comments"></editor>

      <!-- 底部栏发布评论功能及分享 的组件-->
    </div>
    <bottomBar :data="data"></bottomBar>
  </div>
</template>

<script>
import HeaderTop from "@/components/headerTop.vue";
import { getArticleContent, getComment } from "@/api/articlesPage";
import Editor from "@/components/editor.vue";
import bottomBar from "@/components/bottomBar.vue";
export default {
  components: { HeaderTop, Editor, bottomBar },
  name: "serialcontent",
  data() {
    return {
      data: {},
      open: true,
      opens: null,
      bar: 1,
      commentId: "0",
      comments: {},
      show: false,
      isActive: true,
    };
  },
  created() {
    this.getArticle();
  },

  mounted() {
    // this.durations()
    // console.log(this.$refs.audio.duration);
    // console.dir("mounted打印时间",this.$refs.audio.duration)
  },
  computed: {
    //   duration(){
    //      return this.$refs.audio.duration
    //  }
  },
  methods: {
    // 获取文章内容
    async getArticle() {
      const { data } = await getArticleContent(
        this.$route.query.id,
        "serialcontent"
      );
      this.data = data;
      console.log(this.data);
      if (this.data.json_content) {
        this.getComments();
      }
    },
    async getComments() {
      // 获取阅读的评论
      const { data } = await getComment(
        this.data.json_content.type,
        this.data.id,
        this.commentId
      );
      this.comments = data;
      console.log(this.comments);
    },
  },
};
</script>

<style lang="less" scoped>
.wrapper {
  height: 100%;
  z-index: 999999;
}

.block {
  width: 100%;
  height: 140px;
  background-color: #fff;
  text-align: center;
  padding: 10px;
  box-sizing: border-box;
  .Progressbar {
    width: 100%;
    height: 2px;
    background: gray;
    margin: 10px 0 15px 0;
    position: relative;
    .Bared {
      position: absolute;
      top: -2px;
      left: 0;
      width: 0%;
      height: 5px;
      background: palegreen;
      border-top-right-radius: 10px;
      border-bottom-right-radius: 10px;
    }
  }
  .layanchor {
    font-size: 12px;
  }

  .audiocontrol {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 10px;
    .playControl {
      margin: 0 10px;
    }
    img {
      width: 20px;
      height: 20px;
    }
  }
  .leftandright {
    display: flex;
    justify-content: space-between;
  }
}
.box {
  width: 100%;

  background-color: #ffffff;
  box-sizing: border-box;
  .audioOverLay {
    position: fixed;
    top: 60px;
    right: 0;
    width: 30px;
    height: 10px;
    background: gray;
    border-top-left-radius: 30px;
    border-bottom-left-radius: 30px;
    .radius {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background: #000000;
      position: relative;
      .small {
        position: absolute;
        width: 2px;
        height: 2px;
        border-radius: 50%;
        background: #fff;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
      }
    }
  }
  .contents {
    padding: 20px 15px 0 15px;
    margin-top: 30px;
    width: 375px;
    box-sizing: border-box;

    .title {
      font-size: 18px;
      font-weight: bold;
      margin-bottom: 30px;
    }

    .author {
      font-size: 12px;
      color: #000000;
      margin-bottom: 20px;
    }

    .playerBox {
      position: relative;
      margin-bottom: 20px;

      .player {
        width: 100%;
        height: 30px;
        background-color: #ffffff;
        border: 1px solid #000000;
        border-radius: 3px;
        display: flex;
        align-items: center;
        font-size: 12px;

        .playerN {
          padding: 0 5px;
          width: 345px;

          .playEnd {
            display: flex;
            justify-content: space-between;
            align-items: center;

            .right {
              margin-left: 10px;
            }
          }
        }
      }

      .ProgressBar {
        width: 345px;
        height: 30px;
        position: absolute;
        top: 0;
        background: gray;
        opacity: 0.5;
        pointer-events: none;
      }
    }

    ::v-deep .contitle {
      img {
        width: 345px;
      }
      p {
        margin: 10px 0;
      }
      .one-img-container {
        img {
          width: 345px;
        }
      }
    }
  }
}
</style>